#include "LogFile.h"
#include "Logging.h"

std::unique_ptr<yhaida::LogFile> g_logFile;

void outputFunc(const char *msg, int len)
{
  g_logFile->write(msg, len);
}

void flushFunc()
{
  g_logFile->flush();
}

int main(int argc, char *argv[])
{
  char name[256];
  strncpy(name, argv[0], 256);
  // std::cout<<name<<std::endl;
  // std::cout<<basename(name)<<std::endl;
  // const char* name="/home/yhaida/wsl-code/my-server/logging/Logging_test.cpp";
  // std::cout<<basename(name)<<std::endl;
  g_logFile.reset(new yhaida::LogFile(basename(name), 256 * 1024, true, 10));

  yhaida::Logging::setOutput(::outputFunc);
  yhaida::Logging::setFlush(::flushFunc);

  std::string line = "1234567890 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ";

  for (int i = 0; i < 10; ++i)
  {

    LOG_INFO << line;

    usleep(1000);
  }

  // const char line[] = "1234567890 abc";
  // FILE* _fp=fopen("xxxx","ae");

  // int length = fwrite_unlocked(line, 1, sizeof line, _fp);
  // std::cout<<length<<std::endl;

  // fclose(_fp);
}
